package com.cskaoyan.controller.stage;

import com.cskaoyan.exception.MobileValidationException;
import com.cskaoyan.model.Feedback;
import com.cskaoyan.model.vo.ExceptionVO;
import com.cskaoyan.service.FeedbackService;
import com.cskaoyan.service.UserService;
import com.cskaoyan.util.ValidationUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * @ClassName: WxFeedbackController
 * @Description: TODO 微信反馈模块
 * @Author:zhoukang
 * @Date: 2022/5/7 14:30
 * @Version: 1.0
 **/
@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {
    @Autowired
    FeedbackService feedbackService;
    @Autowired
    UserService userService;

    /**
     * @author: zhoukang
     * @description: TODO 提交反馈
     * @date: 2022/5/7 20:19
     */
    @PostMapping("submit")
    public ExceptionVO wxFeedbackSubmit(@RequestBody @Validated Feedback feedbackData, BindingResult bindingResult) throws MobileValidationException {
        ValidationUtil.validMobile(bindingResult);

        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId = userService.getUserIdByUsername(username);

        feedbackData.setUsername(username);
        feedbackData.setUserId(userId);

        feedbackService.insert(feedbackData);
        return new ExceptionVO();
    }

}
